package com.wss.service.impl;

import com.wss.dao.VideoDao;
import com.wss.domain.Message;
import com.wss.domain.Video;
import com.wss.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("videoService")
public class VideoServiceImpl implements VideoService {

    @Autowired
    private VideoDao videoDao;

    @Override
    public List<Video> findVideoAll() {
        System.out.println("业务层：查询所有视频...");
        return videoDao.findVideoAll();
    }

    @Override
    public Video findVideoById(int id) {
        System.out.println("业务层：根据id查询视频...");
        return videoDao.findVideoById(id);
    }

    @Override
    public List<Video> findVideoByTypeId(int vtype_id) {
        System.out.println("业务层：根据vtype_id查询出视频...");
        return videoDao.findVideoByTypeId(vtype_id);
    }

    @Override
    public List<Video> findVideoTop8() {
        System.out.println("业务层：查询最新8条视频...");
        return videoDao.findVideoTop8();
    }

    @Override
    public List<Video> findVideoByUid(int u_id) {
        System.out.println("业务层：根据u_id查询出视频...");
        return videoDao.findVideoByUid(u_id);
    }

    @Override
    public List<Video> findVideoBySearchInput(String input) {
        System.out.println("业务层：根据输入框内容模糊查询出视频...");
        return videoDao.findVideoBySearchInput(input);
    }

    @Override
    public void addVideo(Video video) {
        System.out.println("业务层：添加一条视频...");
        videoDao.addVideo(video);
    }

    @Override
    public void changeVideo(Video video) {
        System.out.println("业务层：修改一条视频...");
        videoDao.changeVideo(video);
    }

    @Override
    public Message deleteVideo(int id) {
        System.out.println("业务层：删除一条视频以及评论和订单...");
        Message message = new Message();
        int resCmt = videoDao.deleteCommentsWithVid(id);
        int resOrder = videoDao.deleteOrdersWithVid(id);
        int res = videoDao.deleteVideo(id);
        if (res > 0){
            message.setResCode(1);
            message.setResultMsg("删除成功");
        }else{
            message.setResCode(0);
            message.setResultMsg("删除失败");
        }
        return message;
    }
}
